package a30_PolymorphicCase;

/**
 * @Author quan
 * @Description 单独的类
 * @Date 2023/3/9 14:27
 */
public class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    //养动物的方法：多态的方式，传递所有子类的父类
    public void keepPet(Animal animal, String something){
        if(animal instanceof Dog){
            System.out.println("年龄为"+name+"的"+"养了一只"+animal.getColor()+"岁的狗");
            Dog dog = (Dog) animal;
            dog.lookHome();
        } else if (animal instanceof Cat) {
            System.out.println("年龄为"+name+"的"+"养了一只"+animal.getColor()+"岁的猫");
            Cat cat = (Cat) animal;
            cat.catchMouse();
        }animal.eat(something);
    }
}
